/**
 * @file eventrunner.c
 * @brief 
 * @author ken (kangjiening@openvalley.net)
 * @version 0.1
 * @date 2023-06-08
 * 
 * @copyright Copyright (c) 2023  湖南开鸿智谷数字产业发展有限公司
 * 
 * @par 修改日志:
 *     @date 2023-06-08
 *     @version 0.2
 *     @author xx
 *     @brief xx
 */
#include <stdio.h>
#include "config.h"
#include "eventrunner.h"

 struct HandlerGather_S {
    EventRunnerType evnetRunnerType;
    void (*handle)(void *args);
};
const struct HandlerGather_S cHanlerGather[] = {
    {EVENTNORMAL,EventRun},
    {EVENTBROKER,EventBroker},
}

/**
 * @brief 创建一个
 * @param  eventRunnerType  
 * @return HandlerEventId* 
 * @author ken (kangjiening@openvalley.net)
 * @date 2023-06-08
 */
EventRunnerId *EventRunnerCreate(EventRunnerType eventRunnerType)
{
    HandlerEventId *eventId = NULL;
    if(eventRunnerType >= EVENTUNUSEED) return NULL;
    eventId->eventRunnerType = eventRunnerType;
    /**创建一个 queue*/
    eventId = (HandlerEventId *)Event_malloc(sizeof(HandlerEventId));
    if(eventId == NULL) return NULL;
   eventId->queueId =  EventQueueCreate();
   if(eventId->queueId < 0)
   {
    Event_free(eventId);
    eventId = NULL;
    return NULL;
   }
   eventId->handle = cHanlerGather[eventId->eventRunnerType].handle;
    ThreadAttr attr = {endpoint->name, MAX_STACK_SIZE, PRI_ABOVE_NORMAL, 0, 0};
    eventId->threadId = (ThreadId)THREAD_Create(eventId->handle, eventId, &attr);
 return eventId;
    
} 
int EventRunnerDelete(EventRunnerId *eventId)
{
    if(eventId != NULL)
    {
        Event_free(eventId);
    }
    return 0;
}

static EventRun(void *args)
{
  HandlerEventId *eventId = (EventRunnerId *)args;
  struct InnerEvent innerEvent;
  while(1)
  {
     if(GetEvent(eventId->queueId, &innerEvent) > 0)
     {
        if(innerEve)
     }
  }
}

